const swaggerJsdoc = require('swagger-jsdoc');

const options = {
    definition: {
        openapi: '3.0.0',
        info: {
            title: 'AutoCost API',
            version: '1.0.0',
            description: 'AutoCost - 汽车费用管理应用后端API',
            contact: {
                name: 'AutoCost Team',
                email: 'support@autocost.com',
            },
        },
        servers: [
            {
                url: 'http://localhost:3000',
                description: 'Development server',
            },
        ],
        components: {
            securitySchemes: {
                bearerAuth: {
                    type: 'http',
                    scheme: 'bearer',
                    bearerFormat: 'JWT',
                },
            },
        },
        security: [
            {
                bearerAuth: [],
            },
        ],
    },
    apis: ['./src/routes/*.ts', './src/controllers/*.ts'],
};

const specs = swaggerJsdoc(options);

// 将swagger规范写入文件
const fs = require('fs');
const path = require('path');

const outputPath = path.join(__dirname, '../swagger.json');
fs.writeFileSync(outputPath, JSON.stringify(specs, null, 2));

console.log(`✅ Swagger JSON 已提取到: ${outputPath}`);
console.log(`📊 API 端点数量: ${Object.keys(specs.paths || {}).length}`); 